package com.physics.mps.module.base;

import com.physics.mps.common.util.AssertUtil;
import com.physics.mps.entity.enums.CodeEnum;
import lombok.Data;

/**
 * 基础计算处理抽象类
 *
 * @author mcsoft
 * @since 2023/9/11
 */
@Data
public abstract class AbstractBaseComputeHandler implements BaseCompute {

    // ~ Variable & Constant
    // ========================================================================================================

    /**
     * 仿真软件APP ID
     */
    private String appId;

    /**
     * 仿真软件模块 ID
     */
    private String appModuleName;

    /**
     * CAE工作目录
     */
    protected String workDir;

    /**
     * CAE安装路径
     */
    protected String caePath;

    /**
     * STP 文件路径
     */
    protected String stpPath;

    // ~ Public method
    // ========================================================================================================

    /**
     * 创建导入依赖命令
     */
    public String createImportCommand() {
        StringBuilder builder = new StringBuilder();
        this.createImportCommandImpl(builder);
        return builder.toString();
    }

    /**
     * 设置工作目录
     */
    public String createSetWorkDirCommand() {
        this.checkCaePath();
        StringBuilder builder = new StringBuilder();
        this.createSetWorkDirCommandImpl(builder);
        return builder.toString();
    }

    /**
     * 创建导入 STP 文件路径
     *
     * @return 导入 STP 文件路径
     */
    public String createImportStpCommand() {
        this.checkStpPath();
        StringBuilder builder = new StringBuilder();
        this.createImportStpCommandImpl(builder);
        return builder.toString();
    }

    /**
     * 创建设置部件命令
     *
     * @return 设置部件命令
     */
    public String createPartCommand() {
        StringBuilder builder = new StringBuilder();
        this.createPartCommandImpl(builder);
        return builder.toString();
    }

    /**
     * 创建 STEP 命令
     */
    public String createStep() {
        StringBuilder builder = new StringBuilder();
        this.createStepImpl(builder);
        return builder.toString();
    }

    /**
     * 创建 STEP & FIELD 命令
     */
    public String createStepAndField() {
        StringBuilder builder = new StringBuilder();
        this.createStepAndFieldImpl(builder);
        return builder.toString();
    }

    /**
     * 创建边界条件命令
     *
     * @return 边界条件命令
     */
    public String createBoundaryCommand() {
        StringBuilder builder = new StringBuilder();
        this.createBoundaryCommandImpl(builder);
        return builder.toString();
    }

    /**
     * 创建输出命令
     */
    public String createOutputCommand() {
        StringBuilder builder = new StringBuilder();
        this.createOutputCommandImpl(builder);
        return builder.toString();
    }

    /**
     * 创建设置网格命令
     *
     * @return 设置网格命令
     */
    public String createPartNameCommand() {
        StringBuilder builder = new StringBuilder();
        this.createPartNameCommandImpl(builder);

        return builder.toString();
    }

    public String createTieCommand() {
        StringBuilder builder = new StringBuilder();
        this.createTieCommandImpl(builder);

        return builder.toString();
    }

    /**
     * 创建设置任务命令
     *
     * @return 设置任务命令
     */
    public String createJobCommand() {
        StringBuilder builder = new StringBuilder();
        this.createJobCommandImpl(builder);
        return builder.toString();
    }

    public String createElemTypeCommand() {
        StringBuilder builder = new StringBuilder();
        this.createElemTypeCommandImpl(builder);
        return builder.toString();
    }

    public String createExportCommand() {
        StringBuilder builder = new StringBuilder();
        this.createExportCommandImpl(builder);
        return builder.toString();
    }

    // ~ Override & abstract method
    // 具体内容由子类实现
    // ========================================================================================================

    public abstract void createImportCommandImpl(StringBuilder builder);

    public abstract void createSetWorkDirCommandImpl(StringBuilder builder);

    public abstract void createImportStpCommandImpl(StringBuilder builder);

    public abstract void createPartCommandImpl(StringBuilder builder);

    public abstract void createStepImpl(StringBuilder builder);

    public abstract void createStepAndFieldImpl(StringBuilder builder);

    public abstract void createBoundaryCommandImpl(StringBuilder builder);

    public abstract void createOutputCommandImpl(StringBuilder builder);

    public abstract void createPartNameCommandImpl(StringBuilder builder);

    public abstract void createTieCommandImpl(StringBuilder builder);

    public abstract void createJobCommandImpl(StringBuilder builder);

    public abstract void createElemTypeCommandImpl(StringBuilder builder);

    public abstract void createExportCommandImpl(StringBuilder builder);

    // ~ Private method
    // ========================================================================================================

    /**
     * 检查 CAE 目录是否为空
     */
    public void checkCaePath() {
        AssertUtil.isBlank(this.caePath, CodeEnum.CAE_PATH_NOT_SET);
    }

    /**
     * 设置工作目录
     */
    public void setWorkDir(String workDir) {
        this.workDir = workDir;
    }

    /**
     * 设置 CAE 目录
     */
    public void setCaePath(String caePath) {
        this.caePath = caePath;
    }

    // 检查stpPath是否为空
    public void checkStpPath() {
        AssertUtil.isBlank(this.stpPath, CodeEnum.STP_PATH_NOT_SET);
    }

    // ~ Autowired
    // ========================================================================================================


}
